<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of v_frq2bark</title>
  <meta name="keywords" content="v_frq2bark">
  <meta name="description" content="V_FRQ2BARK  Convert Hertz to BARK frequency scale BARK=(FRQ)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">v_mfiles</a> &gt; v_frq2bark.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for v_mfiles&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>v_frq2bark
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>V_FRQ2BARK  Convert Hertz to BARK frequency scale BARK=(FRQ)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [b,c] = v_frq2bark(f,m) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">V_FRQ2BARK  Convert Hertz to BARK frequency scale BARK=(FRQ)
       bark = v_frq2bark(frq) converts a vector of frequencies (in Hz)
       to the corresponding values on the BARK scale.
 Inputs: f  matrix of frequencies in Hz
         m  mode options
            'h'   use high frequency correction from [1]
            'l'   use low frequency correction from [1]
            'H'   do not apply any high frequency correction
            'L'   do not apply any low frequency correction
            'z'   use the expressions from Zwicker et al. (1980) for b and c
            's'   use the expression from Schroeder et al. (1979)
            'u'   unipolar version: do not force b to be an odd function
                  This has no effect on the default function which is odd anyway
            'g'   plot a graph

 Outputs: b  bark values
          c  Critical bandwidth: d(freq)/d(bark)</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="v_xticksi.html" class="code" title="function s=v_xticksi(ah)">v_xticksi</a>	V_XTIXKSI labels the x-axis of a plot using SI multipliers S=(AH)</li><li><a href="v_yticksi.html" class="code" title="function s=v_yticksi(ah)">v_yticksi</a>	V_YTIXKSI labels the y-axis of a plot using SI multipliers S=(AH)</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="v_bark2frq.html" class="code" title="function [f,c] = v_bark2frq(b,m)">v_bark2frq</a>	V_BARK2FRQ  Convert the BARK frequency scale to Hertz FRQ=(BARK)</li><li><a href="v_filtbankm.html" class="code" title="function [x,cf,il,ih]=v_filtbankm(p,n,fs,fl,fh,w)">v_filtbankm</a>	V_FILTBANKM determine matrix for a linear/mel/erb/bark-spaced v_filterbank [X,IL,IH]=(P,N,FS,FL,FH,W)</li><li><a href="v_gammabank.html" class="code" title="function [b,a,fx,bx,gd,ph]=v_gammabank(n,fs,w,fc,bw,ph,k)">v_gammabank</a>	V_GAMMABANK gammatone filter bank [b,a,fx,bx,gd]=(n,fs,w,fc,bw,ph,k)</li><li><a href="v_importsii.html" class="code" title="function q=v_importsii(f,m)">v_importsii</a>	V_IMPORTSII calculates the SII importance function per Hz or per Bark Q=(F,M)</li><li><a href="v_melbankm.html" class="code" title="function [x,mc,mn,mx]=v_melbankm(p,n,fs,fl,fh,w)">v_melbankm</a>	V_MELBANKM determine matrix for a mel/erb/bark-spaced v_filterbank [X,MN,MX]=(P,N,FS,FL,FH,W)</li><li><a href="v_spgrambw.html" class="code" title="function [t,f,b]=v_spgrambw(s,fs,varargin)">v_spgrambw</a>	V_SPGRAMBW Draw spectrogram [T,F,B]=(s,fs,mode,bw,fmax,db,tinc,ann)</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [b,c] = v_frq2bark(f,m)</a>
0002 <span class="comment">%V_FRQ2BARK  Convert Hertz to BARK frequency scale BARK=(FRQ)</span>
0003 <span class="comment">%       bark = v_frq2bark(frq) converts a vector of frequencies (in Hz)</span>
0004 <span class="comment">%       to the corresponding values on the BARK scale.</span>
0005 <span class="comment">% Inputs: f  matrix of frequencies in Hz</span>
0006 <span class="comment">%         m  mode options</span>
0007 <span class="comment">%            'h'   use high frequency correction from [1]</span>
0008 <span class="comment">%            'l'   use low frequency correction from [1]</span>
0009 <span class="comment">%            'H'   do not apply any high frequency correction</span>
0010 <span class="comment">%            'L'   do not apply any low frequency correction</span>
0011 <span class="comment">%            'z'   use the expressions from Zwicker et al. (1980) for b and c</span>
0012 <span class="comment">%            's'   use the expression from Schroeder et al. (1979)</span>
0013 <span class="comment">%            'u'   unipolar version: do not force b to be an odd function</span>
0014 <span class="comment">%                  This has no effect on the default function which is odd anyway</span>
0015 <span class="comment">%            'g'   plot a graph</span>
0016 <span class="comment">%</span>
0017 <span class="comment">% Outputs: b  bark values</span>
0018 <span class="comment">%          c  Critical bandwidth: d(freq)/d(bark)</span>
0019 
0020 <span class="comment">%   The Bark scale was defined by in ISO532 and published in [2]. It</span>
0021 <span class="comment">%   was based on a varienty of experiments on the thresholds for complex</span>
0022 <span class="comment">%   sounds, masking, perception of phase and the loudness of complex</span>
0023 <span class="comment">%   sounds. The Bark scale is named in honour of Barkhausen, the creator</span>
0024 <span class="comment">%   of the unit of loudness level [2]. Frequency f lies in critical</span>
0025 <span class="comment">%   band ceil(v_frq2bark(f)). The inverse function is v_bark2frq.</span>
0026 <span class="comment">%</span>
0027 <span class="comment">%   There are many published formulae approximating the Bark scale.</span>
0028 <span class="comment">%   The default is the one from [1] but with a correction at high and</span>
0029 <span class="comment">%   low frequencies to give a better fit to [2] with a continuous derivative</span>
0030 <span class="comment">%   and ensure that 0 Hz = 0 Bark.</span>
0031 <span class="comment">%   The h and l mode options apply the corrections from [1] which are</span>
0032 <span class="comment">%   not as good and do not give a continuous derivative. The H and L</span>
0033 <span class="comment">%   mode options suppress the correction entirely to give a simple formula.</span>
0034 <span class="comment">%   The 's' option uses the less accurate formulae from [3] which have been</span>
0035 <span class="comment">%   widely used in the lterature.</span>
0036 <span class="comment">%   The 'z' option uses the formulae from [4] in which the c output</span>
0037 <span class="comment">%   is not exactly the reciprocal of the derivative of the bark function.</span>
0038 <span class="comment">%</span>
0039 <span class="comment">%   [1] H. Traunmuller, Analytical Expressions for the</span>
0040 <span class="comment">%       Tonotopic Sensory Scale�, J. Acoust. Soc. Am. 88,</span>
0041 <span class="comment">%       1990, pp. 97-100.</span>
0042 <span class="comment">%   [2] E. Zwicker, Subdivision of the audible frequency range into</span>
0043 <span class="comment">%       critical bands, J Accoust Soc Am 33, 1961, p248.</span>
0044 <span class="comment">%   [3] M. R. Schroeder, B. S. Atal, and J. L. Hall. Optimizing digital</span>
0045 <span class="comment">%       speech coders by exploiting masking properties of the human ear.</span>
0046 <span class="comment">%       J. Acoust Soc Amer, 66 (6): 1647�1652, 1979. doi: 10.1121/1.383662.</span>
0047 <span class="comment">%   [4] E. Zwicker and E. Terhardt.  Analytical expressions for</span>
0048 <span class="comment">%       critical-band rate and critical bandwidth as a function of frequency.</span>
0049 <span class="comment">%       J. Acoust Soc Amer, 68 (5): 1523�1525, Nov. 1980.</span>
0050 
0051 <span class="comment">%   The following code reproduces the graphs 3(c) and 3(d) from [1].</span>
0052 <span class="comment">%       b0=(0:0.5:24)';</span>
0053 <span class="comment">%       f0=[[2 5 10 15 20 25 30 35 40 45 51 57 63 70 77 ...</span>
0054 <span class="comment">%           84 92 100 108 117 127 137 148 160 172 185 200 ...</span>
0055 <span class="comment">%           215 232 250 270 290 315]*10 [34 37 40 44 48 53 ...</span>
0056 <span class="comment">%           58 64 70 77 85 95 105 120 135 155]*100]';</span>
0057 <span class="comment">%       b1=v_frq2bark(f0);      b2=v_frq2bark(f0,'lh');</span>
0058 <span class="comment">%       b3=v_frq2bark(f0,'LH'); b4=v_frq2bark(f0,'z');</span>
0059 <span class="comment">%       plot(b0,[b0 b1 b2 b3 b4]-repmat(b0,1,5));</span>
0060 <span class="comment">%       xlabel('Frequency (Bark)'); ylabel('Error (Bark)');</span>
0061 <span class="comment">%       legend('Exact','v_voicebox','Traunmuller1990', ...</span>
0062 <span class="comment">%              'Traunmuller1983','Zwicker1980','Location','South');</span>
0063 
0064 <span class="comment">%      Copyright (C) Mike Brookes 2006-2010</span>
0065 <span class="comment">%      Version: $Id: v_frq2bark.m 10865 2018-09-21 17:22:45Z dmb $</span>
0066 <span class="comment">%</span>
0067 <span class="comment">%   VOICEBOX is a MATLAB toolbox for speech processing.</span>
0068 <span class="comment">%   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html</span>
0069 <span class="comment">%</span>
0070 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0071 <span class="comment">%   This program is free software; you can redistribute it and/or modify</span>
0072 <span class="comment">%   it under the terms of the GNU General Public License as published by</span>
0073 <span class="comment">%   the Free Software Foundation; either version 2 of the License, or</span>
0074 <span class="comment">%   (at your option) any later version.</span>
0075 <span class="comment">%</span>
0076 <span class="comment">%   This program is distributed in the hope that it will be useful,</span>
0077 <span class="comment">%   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
0078 <span class="comment">%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
0079 <span class="comment">%   GNU General Public License for more details.</span>
0080 <span class="comment">%</span>
0081 <span class="comment">%   You can obtain a copy of the GNU General Public License from</span>
0082 <span class="comment">%   http://www.gnu.org/copyleft/gpl.html or by writing to</span>
0083 <span class="comment">%   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.</span>
0084 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0085 <span class="keyword">persistent</span> A B C D P Q R S T U
0086 <span class="keyword">if</span> isempty(P)
0087     A=26.81;
0088     B=1960;
0089     C=-0.53;
0090     D=A*B;
0091     P=(0.53/(3.53)^2);
0092     Q=0.25;
0093     R=20.4;
0094     xy=2;
0095     S=0.5*Q/xy;
0096     T=R+0.5*xy;
0097     U=T-xy;
0098 <span class="keyword">end</span>
0099 <span class="keyword">if</span> nargin&lt;2
0100     m=<span class="string">' '</span>;
0101 <span class="keyword">end</span>
0102 <span class="keyword">if</span> any(m==<span class="string">'u'</span>)
0103     g=f;
0104 <span class="keyword">else</span>
0105     g=abs(f);
0106 <span class="keyword">end</span>
0107 <span class="keyword">if</span> any(m==<span class="string">'z'</span>)
0108     b=13*atan(0.00076*g)+3.5*atan((f/7500).^2);
0109     c=25+75*(1+1.4e-6*f.^2).^0.69;
0110 <span class="keyword">elseif</span> any(m==<span class="string">'s'</span>)
0111     b=7*log(g/650+sqrt(1+(g/650).^2));
0112     c=cosh(b/7)*650/7;
0113 <span class="keyword">else</span>
0114     b=A*g./(B+g)+C;
0115     d=D*(B+g).^(-2);
0116     <span class="keyword">if</span> any(m==<span class="string">'l'</span>)
0117         m1=(b&lt;2);
0118         d(m1)=d(m1)*0.85;
0119         b(m1)=0.3+0.85*b(m1);
0120     <span class="keyword">elseif</span> ~any(m==<span class="string">'L'</span>)
0121         m1=(b&lt;3);
0122         b(m1)=b(m1)+P*(3-b(m1)).^2;
0123         d(m1)=d(m1).*(1-2*P*(3-b(m1)));
0124     <span class="keyword">end</span>
0125     <span class="keyword">if</span> any(m==<span class="string">'h'</span>)
0126         m1=(b&gt;20.1);
0127         d(m1)=d(m1)*1.22;
0128         b(m1)=1.22*b(m1)-4.422;
0129     <span class="keyword">elseif</span> ~any(m==<span class="string">'H'</span>)
0130         m2=(b&gt;T);
0131         m1=(b&gt;U) &amp; ~m2;
0132         b(m1)=b(m1)+S*(b(m1)-U).^2;
0133         b(m2)=(1+Q)*b(m2)-Q*R;
0134         d(m2)=d(m2).*(1+Q);
0135         d(m1)=d(m1).*(1+2*S*(b(m1)-U));
0136     <span class="keyword">end</span>
0137     c=d.^(-1);
0138 <span class="keyword">end</span>
0139 <span class="keyword">if</span> ~any(m==<span class="string">'u'</span>)
0140     b=b.*sign(f);          <span class="comment">% force to be odd</span>
0141 <span class="keyword">end</span>
0142 
0143 <span class="keyword">if</span> ~nargout || any(m==<span class="string">'g'</span>)
0144     subplot(212)
0145     semilogy(f,c,<span class="string">'-r'</span>);
0146     ha=gca;
0147     ylabel([<span class="string">'Critical BW ('</span> <a href="v_yticksi.html" class="code" title="function s=v_yticksi(ah)">v_yticksi</a> <span class="string">'Hz)'</span>]);
0148     xlabel([<span class="string">'Frequency ('</span> <a href="v_xticksi.html" class="code" title="function s=v_xticksi(ah)">v_xticksi</a> <span class="string">'Hz)'</span>]);
0149     subplot(211)
0150     plot(f,b,<span class="string">'x-b'</span>);
0151     hb=gca;
0152     ylabel(<span class="string">'Bark'</span>);
0153     xlabel([<span class="string">'Frequency ('</span> <a href="v_xticksi.html" class="code" title="function s=v_xticksi(ah)">v_xticksi</a> <span class="string">'Hz)'</span>]);
0154     linkaxes([ha hb],<span class="string">'x'</span>);
0155 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>